# -*- coding: utf-8 -*-
"""
Created on Wed Feb 14 18:29:11 2018

@author: Allen
"""
import numpy as np
from sklearn import datasets

boston = datasets.load_boston()
X = boston["data"]
y = boston["target"]

X = X[y<50]
y = y[y<50]

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split( X, y, random_state = 666 )

from sklearn.linear_model import LinearRegression
reg = LinearRegression()
reg.fit( X_train, y_train )
r_squared = reg.score( X_test, y_test ) # 0.80089161995190561

'''
knn也可以解决回归问题，但是有很多超参数需要解决，可以使用网格搜索。
就懒得码代码了
'''